var drawQrcode = require("../../../../utils/weapp.qrcode.min.js");
const app = getApp()
Page({
  data: {
    ewm: '',
    lessonid: '',
    signKey: ''
  },

  startSign: function (e) {
    this.drawEwm(),
      this.teaEwm()
  },

  stopSign: function (e) {
    wx.navigateTo({
      url: '../signByEwmList/signByEwmList?lessonid=' + this.data.lessonid,
    })
  },

  drawEwm: function (e) {
    drawQrcode({
      width: 200,
      height: 200,
      x: 50,
      y: 50,

      canvasId: 'myQrcode',
      text: this.data.ewm,
      // v1.0.0+版本支持在二维码上绘制图片

      image: {
        imageResource: '/images/ewm.jpg',
        dx: 120,
        dy: 120,
        dWidth: 60,
        dHeight: 60
      }
    })
  },

  teaEwm: function (e) {
    var that = this;
    wx.request({
      url: app.globalData.ServerUrl + 'ewm/teaEwm.php',
      data: {
        id: this.data.lessonid,
        ewm: this.data.ewm
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res.data)
        if (res.data) {
          wx.showToast({
            title: '发起考勤成功',
            icon: 'none'
          })
        } else {
          wx.showToast({
            title: '发起考勤失败',
            icon: 'none'
          })
        }
      },
    })
  },



  onLoad: function (e) {
    var that = this;
    that.setData({
      lessonid: e.lessonid,
      ewm: 'lessonid:' + e.lessonid + ',' + 'signkey:' + Math.random().toString(36).substring(2, 12),
    })
    console.log(this.data.ewm)
  },


  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {}
})